home *** CD-ROM | disk | FTP | other *** search
- // Source Code generated by PatchMaker 1.0
- // a sick idea by Paul Baxter
-
- #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
- #error Sorry Can't do that
- #endif
-
- #include <MixedMode.h>
- #include <Appearance.h>
- #include <SpeechSynthesis.h>
- #include <A4Stuff.h>
- #include <string.h>
-
- // enums for routinedescriptor
- enum {
- upp_DrawTextProcInfo = kPascalStackBased
- | STACK_ROUTINE_PARAMETER(1,kFourByteCode)
- | STACK_ROUTINE_PARAMETER(2,kTwoByteCode)
- | STACK_ROUTINE_PARAMETER(3,kTwoByteCode),
- uppPatcExtraInfo
- };
-
- // Function Prototypes
- extern pascal void my_DrawTextPatch(long param1, short param2, short param3);
-
- // Globals to hold original routine descriptors
- RoutineDescriptorPtr gOriginal_DrawText = nil;
-
- // Tell MetroWerks the procInfo for main
- ProcInfoType __procinfo = kPascalStackBased;
- pascal void main(void)
- {
- RoutineDescriptorPtr originaldesc, newdesc, unImplimentedTrapAddr;
- UInt32 size;
- UInt16 index;
- THz theZone;
-
- // get globals
- EnterCodeResource();
- // detach ourselves
- DetachResource(Get1Resource('INIT', 0));
-
- // make sure we are in the system heap
- theZone = GetZone();
- SetZone(SystemZone());
-
- unImplimentedTrapAddr = NGetTrapAddress(_Unimplemented, (_Unimplemented & 0x0800) ? ToolTrap : OSTrap);
-
- originaldesc = NGetTrapAddress(_DrawText, (_DrawText & 0x0800) ? ToolTrap : OSTrap);
- if (originaldesc != unImplimentedTrapAddr) {
- if (originaldesc->goMixedModeTrap != _MixedModeMagic) {
- // Trap is 68K
- size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * 0);
- // allocate new descriptor
- newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
- if (!newdesc) {
- Debugger();
- return;
- }
- // set fields of routine decscriptor
- newdesc->goMixedModeTrap = _MixedModeMagic;
- newdesc->version = 7;
- newdesc->routineDescriptorFlags = 0;
- newdesc->reserved1 = 0;
- newdesc->reserved2 = 0;
- newdesc->selectorInfo = 0;
- newdesc->routineCount = 0;
- index = 0;
- gOriginal_DrawText = originaldesc;
- newdesc->routineRecords[index].procInfo = upp_DrawTextProcInfo;
- newdesc->routineRecords[index].reserved1 = 0;
- newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
- newdesc->routineRecords[index].routineFlags = 4;
- newdesc->routineRecords[index].procDescriptor = (ProcPtr)my_DrawTextPatch;
- newdesc->routineRecords[index].reserved2 = 0;
- newdesc->routineRecords[index].selector = 0;
- }
- else {
- // Trap is PPC
- size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * originaldesc->routineCount);
- newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
- if (!newdesc) {
- DebugStr("\pFailed to allocate RoutineDescriptor");
- return;
- }
- BlockMoveData(originaldesc, newdesc, size);
- gOriginal_DrawText = originaldesc;
- index = 0;
- newdesc->routineRecords[index].procDescriptor = (ProcPtr)my_DrawTextPatch;
- newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
- }
- NSetTrapAddress((UniversalProcPtr) newdesc, _DrawText, (_DrawText & 0x0800) ? ToolTrap : OSTrap);
- }
-
- // restore to original heap
- SetZone(theZone);
- // restore globals
- ExitCodeResource();
- }
-
- pascal void my_DrawTextPatch(long param1, short param2, short param3)
- {
- // Get globals
- EnterCodeResource();
-
- // if the string is "OK"
- if ((param3 == 2) && ((char *)param1)[param2] == 'O' && ((char *)param1)[param2+1] == 'K')
- {
- // replace param1 with my string
- ((char *)param1)[0] = 5;
- strcpy(((char *)param1)+param2, "Nooo!");
- param3 = 5;
- }
-
- CALL_THREE_PARAMETER_UPP( gOriginal_DrawText, upp_DrawTextProcInfo, param1, param2, param3);
-
- // Release globals
- ExitCodeResource();
- }
-
-